package structual_pattern.flyweight_pattern;

import java.util.Hashtable;

public class FlyweightPattern {
    public static void main(String[] args) {

    }
}
abstract class IgoChessman{
    public abstract String getColor();

    public void display(){
        System.out.println("棋子颜色");
    }
}
class BlackIgoChessman extends IgoChessman{

    @Override
    public String getColor() {
        return "black";
    }
}

class WhiteigoChessman extends IgoChessman{


    @Override
    public String getColor() {
        return "white";
    }
}
class IgoChessmanFactory{
    private static IgoChessmanFactory instance = new IgoChessmanFactory();
    private static Hashtable ht;
    private IgoChessmanFactory(){
        ht = new Hashtable();
        IgoChessman black,white;
        black = new BlackIgoChessman();
        white = new WhiteigoChessman();
        ht.put("b", black);
        ht.put("w", white);
    }
    public static IgoChessmanFactory getInstance(){
        return instance;
    }
    public static IgoChessman getIgochessman(String color){
        return (IgoChessman) ht.get(color);
    }
}